import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:share_fit/app/controllers/space/person/person_logic.dart';
import 'package:share_fit/app/helper/ext/tr_ext.dart';
import 'package:share_fit/generated/locales.g.dart';

class TextFieldDialog extends Dialog {

  final logic = Get.put(PersonLogic());
  final String title;
  final Function callback;
  String inputVal = "";

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
        child: Material(
            type: MaterialType.transparency,
            child: Center(
                child: GestureDetector(
                    onTap: () {
                      print('～');
                    },
                    child: Container(
                        width: 916.w,
                        height: 736.w,
                        decoration: BoxDecoration(
                          borderRadius: BorderRadius.circular(10),
                          color: Colors.white,
                        ),
                        child: Stack(
                            alignment: Alignment.bottomCenter,
                            children: <Widget>[
                              Positioned(
                                  top: 0,
                                  child: Container(
                                      alignment: Alignment.center,
                                      margin: EdgeInsets.fromLTRB(0, 60.h, 0, 60.h),
                                      child: Text(title,
                                          style: TextStyle(fontSize: 54.sp, color: Color(0xff000000),))
                                  )
                              ),
                              Container(
                                  width: double.infinity,
                                  margin: EdgeInsets.fromLTRB(0, 0, 0, 125.h),
                                  alignment: Alignment.center,
                                  child: TextField(
                                    autofocus: true,
                                    textAlign: TextAlign.center,
                                    maxLines: 1,
                                    cursorColor: Colors.grey,
                                    decoration: const InputDecoration(
                                      focusedBorder: UnderlineInputBorder(
                                        borderSide: BorderSide(
                                          color: Colors.grey
                                        )
                                      ),
                                      focusedErrorBorder: UnderlineInputBorder(
                                          borderSide: BorderSide(color: Colors.black)
                                      ),
                                    ),
                                    // onSubmitted: (value){
                                    //   inputVal = value;
                                    //   callback(value);
                                    //   print('！！！' + inputVal);
                                    //   Navigator.pop(context);
                                    // },
                                    // controller: _controller,
                                    onChanged: (value) {
                                      inputVal = value;
                                      logic.setNickName(value);
                                    },
                                  )
                              ),
                              Container(
                                  height: 43,
                                  child: Row(
                                      children: <Widget>[
                                        Expanded(
                                            flex: 1,
                                            child: GestureDetector(
                                                behavior: HitTestBehavior.opaque,
                                                child: Container(
                                                    height: double.infinity,
                                                    alignment: Alignment.center,
                                                    decoration: BoxDecoration(
                                                        border: Border(right: BorderSide(width: 1,color: Color(0xffEFEFF4)))
                                                    ),
                                                    child: Text(
                                                        LocaleKeys.person_choice_cancel.ts,
                                                        textAlign: TextAlign.center,
                                                        style: TextStyle(color: Colors.black, fontSize: 54.sp, fontWeight: FontWeight.w400)
                                                    )
                                                ),
                                                onTap: () {
                                                  logic.setNickName(logic.read('space_person_name', defaultValue: '', global: true));
                                                  Navigator.pop(context);
                                                }
                                            )
                                        ),
                                        Expanded(
                                            flex: 1,
                                            child: GestureDetector(
                                                behavior: HitTestBehavior.opaque,
                                                child: Container(
                                                    height: double.infinity,
                                                    alignment: Alignment.center,
                                                    child: Text(
                                                        LocaleKeys.person_choice_submit.ts,
                                                        textAlign: TextAlign.center,
                                                        style: TextStyle(color: Colors.black, fontSize: 54.sp,)
                                                    )
                                                ),
                                                onTap: () {
                                                  logic.save('space_person_name', logic.state.nickName, global: true);
                                                  callback(inputVal);
                                                  Navigator.pop(context);
                                                }))
                                      ]))
                            ])
                    )))),
        onTap: () {
          Navigator.pop(context);
        }
    );
  }

  TextFieldDialog({required this.title, required this.callback}); // 内容
}